package doyouknow.group.CnAndZhb.controller;

import doyouknow.group.CnAndZhb.entity.TbAdmin;
import doyouknow.group.CnAndZhb.entity.TbSceneGwMap;
import doyouknow.group.CnAndZhb.error.BusinessException;
import doyouknow.group.CnAndZhb.error.EnumBusinessError;
import doyouknow.group.CnAndZhb.response.BaseControllerReturn;
import doyouknow.group.CnAndZhb.service.TbSceneGwMapService;
import doyouknow.group.CnAndZhb.utils.SerializedField;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * (TbSceneGwMap)表控制层
 *
 * @author cn
 * @since 2020-11-03 21:05:02
 */
@RestController
@RequestMapping("tbSceneGwMap")
public class TbSceneGwMapController extends BaseController{
    /**
     * 服务对象
     */
    @Resource
    private TbSceneGwMapService tbSceneGwMapService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("selectOne")
    public TbSceneGwMap selectOne(Integer id) {
        return this.tbSceneGwMapService.queryById(id);
    }


    @GetMapping("selectOneByMac")
    @SerializedField(includes = {"id","gwMac","sceneName","body","isMofei","isBz","bzName"})
    public Object selectOngByMac(String mac) throws BusinessException{
        if (StringUtils.isEmpty(mac)) {
            throw new BusinessException(EnumBusinessError.PARAMETER_VALIDATION_ERROR,"请输入正确的网关mac");
        }
        List<TbSceneGwMap> tbSceneGwMaps =  tbSceneGwMapService.isSoEasy(mac);
        return BaseControllerReturn.create(tbSceneGwMaps,null);

    }

}